#include <iostream>
#include <string>
#include "msg.pb.h"
using namespace std;

int main()
{
    pbspace::msg obj;
    int cnt = 0;
    obj.add_msgbody("hello");
    cnt++;
    obj.add_msgbody("world");
    cnt++;
    obj.add_msgbody("!");
    cnt++;
    obj.set_count(cnt);
    obj.type_Name(pbspace::msg::TYPE2);

    string buffer;
    // obj.SerializePartialToString(&buffer);
    obj.SerializeToString(&buffer);

    ////////////////

    pbspace::msg recv;
    // recv.ParsePartialFromString(buffer);
    recv.ParseFromString(buffer);
    cout << "msg count = " << recv.count() << endl;
    for (int i = 0; i < recv.msgbody_size(); i++)
    {
        const string &msgbdy = recv.msgbody(i);
        cout << "msgbody " << i + 1 << " " << msgbdy << endl;
    }
    string type = recv.GetTypeName();
    cout << "type = " << type << endl;
    switch (atoi(type.c_str()))
    {
    case 1:
        cout << "TYPE = 1\n";
        break;
    case 0:
        cout << "TYPE = 0\n";
        break;
    case 2:
        cout << "TYPE = 2\n";
        break;
    default:
        cout << "error: \n";
        break;
    }

    return 0;
}